<?php

namespace app\common\model;

class ArticleCategory extends BaseModel
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'article_category';

    // 追加属性
    protected $append = [
        'created_at_text',
    ];

    // 获取格式化后的创建时间
    public function getCreatedAtTextAttr($value, $data)
    {
        return isset($data['created_at']) ? date('Y-m-d H:i:s', strtotime($data['created_at'])) : '';
    }

    // 关联文章
    public function articles()
    {
        return $this->hasMany('Article', 'category_id', 'id');
    }

    // 获取分类列表
    public static function getList($where = [], $order = ['created_at' => 'desc'])
    {
        return self::where($where)
            ->order($order)
            ->select();
    }
}
